package org.rsbot.script.internal.wrappers;

import org.rsbot.client.NodeSub;
import org.rsbot.client.NodeSubQueue;

public class Queue<N extends NodeSub>
{
  private final NodeSubQueue nl;
  private NodeSub current;

  public Queue(NodeSubQueue paramNodeSubQueue)
  {
    this.nl = paramNodeSubQueue;
  }

  public int size() {
    int i = 0;
    NodeSub localNodeSub = this.nl.getTail().getPrevSub();

    while (localNodeSub != this.nl.getTail()) {
      localNodeSub = localNodeSub.getPrevSub();
      i++;
    }

    return i;
  }

  public N getHead() {
    NodeSub localNodeSub = this.nl.getTail().getNextSub();

    if (localNodeSub == this.nl.getTail()) {
      this.current = null;
      return null;
    }
    this.current = localNodeSub.getNextSub();

    return localNodeSub;
  }

  public N getNext() {
    NodeSub localNodeSub = this.current;

    if (localNodeSub == this.nl.getTail()) {
      this.current = null;
      return null;
    }
    this.current = localNodeSub.getNextSub();

    return localNodeSub;
  }
}